<template>
  <div class="employees-detail-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账号设置">
            <!-- 放置表单 -->
            <el-form
              ref="userForm"
              :model="userinfo"
              :rules="rules"
              label-width="120px"
              style="margin-left: 120px; margin-top: 30px"
            >
              <el-form-item prop="username" label="姓名:">
                <el-input
                  v-model="userinfo.username"
                  placeholder="请输入姓名"
                  style="width: 300px"
                />
              </el-form-item>
              <el-form-item prop="newPassword" label="新密码:">
                <el-input
                  v-model="userinfo.newPassword"
                  placeholder="请输入新密码"
                  style="width: 300px"
                  type="password"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="serveuser">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <!-- 内容 -->

            <el-tooltip class="tooltip-box" content="打印基本个人信息">
              <router-link :to="`/employees/print/${userId}?type=personal`">
                <i class="el-icon-printer" />
              </router-link>
            </el-tooltip>

            <userinfo> </userinfo>
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <el-tooltip class="tooltip-box" content="打印基本岗位信息">
              <router-link :to="`/employees/print/${userId}?type=job`">
                <i class="el-icon-printer" />
              </router-link>
            </el-tooltip>
            <!-- 内容 -->
            <jobinfo></jobinfo>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getsysuserinfoapi } from '@/api/user'
import { resetuserinfoapi } from '@/api/employes'
// import userinfoVue from './userinfo.vue'

// import jobinfoVue from './jobinfo.vue'
import userinfo from '@/views/employees/componments/userinfo.vue'
import jobinfo from '@/views/employees/componments/jobinfo.vue'
export default {
  components: {
    userinfo,
    jobinfo
  },

  // name: 'EmployeesDetail',
  data() {
    return {
      userinfo: {
        username: '',
        newPassword: ''
      },
      rules: {
        username: [
          {
            required: true,
            message: '姓名不能为空',
            trigger: ['blur', 'change']
          }
        ],
        newPassword: [
          {
            min: 6,
            max: 9,
            message: '密码必须是6-9位',
            trigger: ['blur', 'change']
          }
        ]
      }
    }
  },
  computed: {
    userId() {
      return this.$route.params.id
    }
  },
  async created() {
    const { data } = await getsysuserinfoapi(this.userId)
    this.userinfo = data
  },
  methods: {
    serveuser() {
      this.$refs.userForm.validate(async (flag) => {
        if (!flag) return
        await resetuserinfoapi({
          ...this.userinfo,
          password: this.userinfo.newPassword
        })
        this.$message.success('保存成功')
      })
    }
  }
}
</script>
<style lang="scss" scoped>
// .employees-detail-container {
//   .el-tab-pane {
//     padding-top: 10px;
//   }
//   .tooltip-box {
//     position: absolute;
//     right: 30px;
//     top: 10px;
//     z-index: 999;
//   }
// }
</style>
